// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.


suite("test_cast_to_float_from_datetimev2_0_part2") {

    // This test case is generated from the correspoinding be UT test case,
    // update this case if the correspoinding be UT test case is updated,
    // e.g.: ../run-be-ut.sh --run --filter=FunctionCastToDecimalTest.* --gen_regression_case
    sql "drop table if exists test_cast_to_float_from_datetimev2_0_part2_2_nullable;"
    sql "create table test_cast_to_float_from_datetimev2_0_part2_2_nullable(f1 int, f2 datetimev2(0)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_datetimev2_0_part2_2_nullable values (0, "0001-01-01 23:01:01"),(1, "0001-01-01 23:01:01"),(2, "0001-01-01 23:01:01"),(3, "0001-01-01 23:01:59"),(4, "0001-01-01 23:01:59"),(5, "0001-01-01 23:01:59"),(6, "0001-01-01 23:59:00"),(7, "0001-01-01 23:59:00"),(8, "0001-01-01 23:59:00"),(9, "0001-01-01 23:59:01"),(10, "0001-01-01 23:59:01"),(11, "0001-01-01 23:59:01"),(12, "0001-01-01 23:59:59"),(13, "0001-01-01 23:59:59"),(14, "0001-01-01 23:59:59"),(15, "0001-01-28 00:00:00"),(16, "0001-01-28 00:00:00"),(17, "0001-01-28 00:00:00"),(18, "0001-01-28 00:00:01"),(19, "0001-01-28 00:00:01"),
      (20, "0001-01-28 00:00:01"),(21, "0001-01-28 00:00:59"),(22, "0001-01-28 00:00:59"),(23, "0001-01-28 00:00:59"),(24, "0001-01-28 00:01:00"),(25, "0001-01-28 00:01:00"),(26, "0001-01-28 00:01:00"),(27, "0001-01-28 00:01:01"),(28, "0001-01-28 00:01:01"),(29, "0001-01-28 00:01:01"),(30, "0001-01-28 00:01:59"),(31, "0001-01-28 00:01:59"),(32, "0001-01-28 00:01:59"),(33, "0001-01-28 00:59:00"),(34, "0001-01-28 00:59:00"),(35, "0001-01-28 00:59:00"),(36, "0001-01-28 00:59:01"),(37, "0001-01-28 00:59:01"),(38, "0001-01-28 00:59:01"),(39, "0001-01-28 00:59:59"),
      (40, "0001-01-28 00:59:59"),(41, "0001-01-28 00:59:59"),(42, "0001-01-28 01:00:00"),(43, "0001-01-28 01:00:00"),(44, "0001-01-28 01:00:00"),(45, "0001-01-28 01:00:01"),(46, "0001-01-28 01:00:01"),(47, "0001-01-28 01:00:01"),(48, "0001-01-28 01:00:59"),(49, "0001-01-28 01:00:59"),(50, "0001-01-28 01:00:59"),(51, "0001-01-28 01:01:00"),(52, "0001-01-28 01:01:00"),(53, "0001-01-28 01:01:00"),(54, "0001-01-28 01:01:01"),(55, "0001-01-28 01:01:01"),(56, "0001-01-28 01:01:01"),(57, "0001-01-28 01:01:59"),(58, "0001-01-28 01:01:59"),(59, "0001-01-28 01:01:59"),
      (60, "0001-01-28 01:59:00"),(61, "0001-01-28 01:59:00"),(62, "0001-01-28 01:59:00"),(63, "0001-01-28 01:59:01"),(64, "0001-01-28 01:59:01"),(65, "0001-01-28 01:59:01"),(66, "0001-01-28 01:59:59"),(67, "0001-01-28 01:59:59"),(68, "0001-01-28 01:59:59"),(69, "0001-01-28 23:00:00"),(70, "0001-01-28 23:00:00"),(71, "0001-01-28 23:00:00"),(72, "0001-01-28 23:00:01"),(73, "0001-01-28 23:00:01"),(74, "0001-01-28 23:00:01"),(75, "0001-01-28 23:00:59"),(76, "0001-01-28 23:00:59"),(77, "0001-01-28 23:00:59"),(78, "0001-01-28 23:01:00"),(79, "0001-01-28 23:01:00"),
      (80, "0001-01-28 23:01:00"),(81, "0001-01-28 23:01:01"),(82, "0001-01-28 23:01:01"),(83, "0001-01-28 23:01:01"),(84, "0001-01-28 23:01:59"),(85, "0001-01-28 23:01:59"),(86, "0001-01-28 23:01:59"),(87, "0001-01-28 23:59:00"),(88, "0001-01-28 23:59:00"),(89, "0001-01-28 23:59:00"),(90, "0001-01-28 23:59:01"),(91, "0001-01-28 23:59:01"),(92, "0001-01-28 23:59:01"),(93, "0001-01-28 23:59:59"),(94, "0001-01-28 23:59:59"),(95, "0001-01-28 23:59:59"),(96, "0001-12-01 00:00:00"),(97, "0001-12-01 00:00:00"),(98, "0001-12-01 00:00:00"),(99, "0001-12-01 00:00:01"),
      (100, "0001-12-01 00:00:01"),(101, "0001-12-01 00:00:01"),(102, "0001-12-01 00:00:59"),(103, "0001-12-01 00:00:59"),(104, "0001-12-01 00:00:59"),(105, "0001-12-01 00:01:00"),(106, "0001-12-01 00:01:00"),(107, "0001-12-01 00:01:00"),(108, "0001-12-01 00:01:01"),(109, "0001-12-01 00:01:01"),(110, "0001-12-01 00:01:01"),(111, "0001-12-01 00:01:59"),(112, "0001-12-01 00:01:59"),(113, "0001-12-01 00:01:59"),(114, "0001-12-01 00:59:00"),(115, "0001-12-01 00:59:00"),(116, "0001-12-01 00:59:00"),(117, "0001-12-01 00:59:01"),(118, "0001-12-01 00:59:01"),(119, "0001-12-01 00:59:01"),
      (120, "0001-12-01 00:59:59"),(121, "0001-12-01 00:59:59"),(122, "0001-12-01 00:59:59"),(123, "0001-12-01 01:00:00"),(124, "0001-12-01 01:00:00"),(125, "0001-12-01 01:00:00"),(126, "0001-12-01 01:00:01"),(127, "0001-12-01 01:00:01"),(128, "0001-12-01 01:00:01"),(129, "0001-12-01 01:00:59"),(130, "0001-12-01 01:00:59"),(131, "0001-12-01 01:00:59"),(132, "0001-12-01 01:01:00"),(133, "0001-12-01 01:01:00"),(134, "0001-12-01 01:01:00"),(135, "0001-12-01 01:01:01"),(136, "0001-12-01 01:01:01"),(137, "0001-12-01 01:01:01"),(138, "0001-12-01 01:01:59"),(139, "0001-12-01 01:01:59"),
      (140, "0001-12-01 01:01:59"),(141, "0001-12-01 01:59:00"),(142, "0001-12-01 01:59:00"),(143, "0001-12-01 01:59:00"),(144, "0001-12-01 01:59:01"),(145, "0001-12-01 01:59:01"),(146, "0001-12-01 01:59:01"),(147, "0001-12-01 01:59:59"),(148, "0001-12-01 01:59:59"),(149, "0001-12-01 01:59:59"),(150, "0001-12-01 23:00:00"),(151, "0001-12-01 23:00:00"),(152, "0001-12-01 23:00:00"),(153, "0001-12-01 23:00:01"),(154, "0001-12-01 23:00:01"),(155, "0001-12-01 23:00:01"),(156, "0001-12-01 23:00:59"),(157, "0001-12-01 23:00:59"),(158, "0001-12-01 23:00:59"),(159, "0001-12-01 23:01:00"),
      (160, "0001-12-01 23:01:00"),(161, "0001-12-01 23:01:00"),(162, "0001-12-01 23:01:01"),(163, "0001-12-01 23:01:01"),(164, "0001-12-01 23:01:01"),(165, "0001-12-01 23:01:59"),(166, "0001-12-01 23:01:59"),(167, "0001-12-01 23:01:59"),(168, "0001-12-01 23:59:00"),(169, "0001-12-01 23:59:00"),(170, "0001-12-01 23:59:00"),(171, "0001-12-01 23:59:01"),(172, "0001-12-01 23:59:01"),(173, "0001-12-01 23:59:01"),(174, "0001-12-01 23:59:59"),(175, "0001-12-01 23:59:59"),(176, "0001-12-01 23:59:59"),(177, "0001-12-28 00:00:00"),(178, "0001-12-28 00:00:00"),(179, "0001-12-28 00:00:00"),
      (180, "0001-12-28 00:00:01"),(181, "0001-12-28 00:00:01"),(182, "0001-12-28 00:00:01"),(183, "0001-12-28 00:00:59"),(184, "0001-12-28 00:00:59"),(185, "0001-12-28 00:00:59"),(186, "0001-12-28 00:01:00"),(187, "0001-12-28 00:01:00"),(188, "0001-12-28 00:01:00"),(189, "0001-12-28 00:01:01"),(190, "0001-12-28 00:01:01"),(191, "0001-12-28 00:01:01"),(192, "0001-12-28 00:01:59"),(193, "0001-12-28 00:01:59"),(194, "0001-12-28 00:01:59")
      ,(195, null);
    """

    sql "set enable_strict_cast=true;"

    test {
        sql """select f1, cast(f2 as float) from test_cast_to_float_from_datetimev2_0_part2_2_nullable order by 1;"""
        exception ""
    }
    sql "set enable_strict_cast=false;"
    qt_sql_2_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_datetimev2_0_part2_2_nullable order by 1;'

    sql "drop table if exists test_cast_to_float_from_datetimev2_0_part2_2_not_nullable;"
    sql "create table test_cast_to_float_from_datetimev2_0_part2_2_not_nullable(f1 int, f2 datetimev2(0)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_datetimev2_0_part2_2_not_nullable values (0, "0001-01-01 23:01:01"),(1, "0001-01-01 23:01:01"),(2, "0001-01-01 23:01:01"),(3, "0001-01-01 23:01:59"),(4, "0001-01-01 23:01:59"),(5, "0001-01-01 23:01:59"),(6, "0001-01-01 23:59:00"),(7, "0001-01-01 23:59:00"),(8, "0001-01-01 23:59:00"),(9, "0001-01-01 23:59:01"),(10, "0001-01-01 23:59:01"),(11, "0001-01-01 23:59:01"),(12, "0001-01-01 23:59:59"),(13, "0001-01-01 23:59:59"),(14, "0001-01-01 23:59:59"),(15, "0001-01-28 00:00:00"),(16, "0001-01-28 00:00:00"),(17, "0001-01-28 00:00:00"),(18, "0001-01-28 00:00:01"),(19, "0001-01-28 00:00:01"),
      (20, "0001-01-28 00:00:01"),(21, "0001-01-28 00:00:59"),(22, "0001-01-28 00:00:59"),(23, "0001-01-28 00:00:59"),(24, "0001-01-28 00:01:00"),(25, "0001-01-28 00:01:00"),(26, "0001-01-28 00:01:00"),(27, "0001-01-28 00:01:01"),(28, "0001-01-28 00:01:01"),(29, "0001-01-28 00:01:01"),(30, "0001-01-28 00:01:59"),(31, "0001-01-28 00:01:59"),(32, "0001-01-28 00:01:59"),(33, "0001-01-28 00:59:00"),(34, "0001-01-28 00:59:00"),(35, "0001-01-28 00:59:00"),(36, "0001-01-28 00:59:01"),(37, "0001-01-28 00:59:01"),(38, "0001-01-28 00:59:01"),(39, "0001-01-28 00:59:59"),
      (40, "0001-01-28 00:59:59"),(41, "0001-01-28 00:59:59"),(42, "0001-01-28 01:00:00"),(43, "0001-01-28 01:00:00"),(44, "0001-01-28 01:00:00"),(45, "0001-01-28 01:00:01"),(46, "0001-01-28 01:00:01"),(47, "0001-01-28 01:00:01"),(48, "0001-01-28 01:00:59"),(49, "0001-01-28 01:00:59"),(50, "0001-01-28 01:00:59"),(51, "0001-01-28 01:01:00"),(52, "0001-01-28 01:01:00"),(53, "0001-01-28 01:01:00"),(54, "0001-01-28 01:01:01"),(55, "0001-01-28 01:01:01"),(56, "0001-01-28 01:01:01"),(57, "0001-01-28 01:01:59"),(58, "0001-01-28 01:01:59"),(59, "0001-01-28 01:01:59"),
      (60, "0001-01-28 01:59:00"),(61, "0001-01-28 01:59:00"),(62, "0001-01-28 01:59:00"),(63, "0001-01-28 01:59:01"),(64, "0001-01-28 01:59:01"),(65, "0001-01-28 01:59:01"),(66, "0001-01-28 01:59:59"),(67, "0001-01-28 01:59:59"),(68, "0001-01-28 01:59:59"),(69, "0001-01-28 23:00:00"),(70, "0001-01-28 23:00:00"),(71, "0001-01-28 23:00:00"),(72, "0001-01-28 23:00:01"),(73, "0001-01-28 23:00:01"),(74, "0001-01-28 23:00:01"),(75, "0001-01-28 23:00:59"),(76, "0001-01-28 23:00:59"),(77, "0001-01-28 23:00:59"),(78, "0001-01-28 23:01:00"),(79, "0001-01-28 23:01:00"),
      (80, "0001-01-28 23:01:00"),(81, "0001-01-28 23:01:01"),(82, "0001-01-28 23:01:01"),(83, "0001-01-28 23:01:01"),(84, "0001-01-28 23:01:59"),(85, "0001-01-28 23:01:59"),(86, "0001-01-28 23:01:59"),(87, "0001-01-28 23:59:00"),(88, "0001-01-28 23:59:00"),(89, "0001-01-28 23:59:00"),(90, "0001-01-28 23:59:01"),(91, "0001-01-28 23:59:01"),(92, "0001-01-28 23:59:01"),(93, "0001-01-28 23:59:59"),(94, "0001-01-28 23:59:59"),(95, "0001-01-28 23:59:59"),(96, "0001-12-01 00:00:00"),(97, "0001-12-01 00:00:00"),(98, "0001-12-01 00:00:00"),(99, "0001-12-01 00:00:01"),
      (100, "0001-12-01 00:00:01"),(101, "0001-12-01 00:00:01"),(102, "0001-12-01 00:00:59"),(103, "0001-12-01 00:00:59"),(104, "0001-12-01 00:00:59"),(105, "0001-12-01 00:01:00"),(106, "0001-12-01 00:01:00"),(107, "0001-12-01 00:01:00"),(108, "0001-12-01 00:01:01"),(109, "0001-12-01 00:01:01"),(110, "0001-12-01 00:01:01"),(111, "0001-12-01 00:01:59"),(112, "0001-12-01 00:01:59"),(113, "0001-12-01 00:01:59"),(114, "0001-12-01 00:59:00"),(115, "0001-12-01 00:59:00"),(116, "0001-12-01 00:59:00"),(117, "0001-12-01 00:59:01"),(118, "0001-12-01 00:59:01"),(119, "0001-12-01 00:59:01"),
      (120, "0001-12-01 00:59:59"),(121, "0001-12-01 00:59:59"),(122, "0001-12-01 00:59:59"),(123, "0001-12-01 01:00:00"),(124, "0001-12-01 01:00:00"),(125, "0001-12-01 01:00:00"),(126, "0001-12-01 01:00:01"),(127, "0001-12-01 01:00:01"),(128, "0001-12-01 01:00:01"),(129, "0001-12-01 01:00:59"),(130, "0001-12-01 01:00:59"),(131, "0001-12-01 01:00:59"),(132, "0001-12-01 01:01:00"),(133, "0001-12-01 01:01:00"),(134, "0001-12-01 01:01:00"),(135, "0001-12-01 01:01:01"),(136, "0001-12-01 01:01:01"),(137, "0001-12-01 01:01:01"),(138, "0001-12-01 01:01:59"),(139, "0001-12-01 01:01:59"),
      (140, "0001-12-01 01:01:59"),(141, "0001-12-01 01:59:00"),(142, "0001-12-01 01:59:00"),(143, "0001-12-01 01:59:00"),(144, "0001-12-01 01:59:01"),(145, "0001-12-01 01:59:01"),(146, "0001-12-01 01:59:01"),(147, "0001-12-01 01:59:59"),(148, "0001-12-01 01:59:59"),(149, "0001-12-01 01:59:59"),(150, "0001-12-01 23:00:00"),(151, "0001-12-01 23:00:00"),(152, "0001-12-01 23:00:00"),(153, "0001-12-01 23:00:01"),(154, "0001-12-01 23:00:01"),(155, "0001-12-01 23:00:01"),(156, "0001-12-01 23:00:59"),(157, "0001-12-01 23:00:59"),(158, "0001-12-01 23:00:59"),(159, "0001-12-01 23:01:00"),
      (160, "0001-12-01 23:01:00"),(161, "0001-12-01 23:01:00"),(162, "0001-12-01 23:01:01"),(163, "0001-12-01 23:01:01"),(164, "0001-12-01 23:01:01"),(165, "0001-12-01 23:01:59"),(166, "0001-12-01 23:01:59"),(167, "0001-12-01 23:01:59"),(168, "0001-12-01 23:59:00"),(169, "0001-12-01 23:59:00"),(170, "0001-12-01 23:59:00"),(171, "0001-12-01 23:59:01"),(172, "0001-12-01 23:59:01"),(173, "0001-12-01 23:59:01"),(174, "0001-12-01 23:59:59"),(175, "0001-12-01 23:59:59"),(176, "0001-12-01 23:59:59"),(177, "0001-12-28 00:00:00"),(178, "0001-12-28 00:00:00"),(179, "0001-12-28 00:00:00"),
      (180, "0001-12-28 00:00:01"),(181, "0001-12-28 00:00:01"),(182, "0001-12-28 00:00:01"),(183, "0001-12-28 00:00:59"),(184, "0001-12-28 00:00:59"),(185, "0001-12-28 00:00:59"),(186, "0001-12-28 00:01:00"),(187, "0001-12-28 00:01:00"),(188, "0001-12-28 00:01:00"),(189, "0001-12-28 00:01:01"),(190, "0001-12-28 00:01:01"),(191, "0001-12-28 00:01:01"),(192, "0001-12-28 00:01:59"),(193, "0001-12-28 00:01:59"),(194, "0001-12-28 00:01:59");
    """

    sql "set enable_strict_cast=true;"

    test {
        sql """select f1, cast(f2 as float) from test_cast_to_float_from_datetimev2_0_part2_2_not_nullable order by 1;"""
        exception ""
    }
    sql "set enable_strict_cast=false;"
    qt_sql_2_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_datetimev2_0_part2_2_not_nullable order by 1;'

}